import time
from base.baseApp import BaseApp
from selenium.webdriver.common.by import By
from appium import webdriver
from page.mailList import OrgPageElement
import allure

class OrgPage(BaseApp):

    def __init__(self, driver):
        super().__init__(driver)

    def create_org(self, org_name):
        # 进入企业微信首页
        # self.driver.start_activity("com.tencent.wework", ".launch.WwMainActivity")
        with allure.step("进入企业微信首页"):
            self.get_index("com.tencent.wework", ".launch.WwMainActivity")
        # 点击-通讯录按钮
        with allure.step("点击-通讯录按钮"):
            self.my_click(OrgPageElement.index_mail_list_button)
        # 进入通讯录设置
        with allure.step("进入通讯录设置"):
            self.my_click(OrgPageElement.mail_list_page_settings_button)
        # 点击-添加子部门
        with allure.step("点击-添加子部门"):
            self.my_click(OrgPageElement.add_org_button)
        # 输入部门名称
        with allure.step("输入部门名称"):
            if org_name:
                self.my_send_keys(OrgPageElement.org_name_input, org_name)
        # 点击-确定
        with allure.step("点击-确定"):
            self.my_click(OrgPageElement.define_button)

# desirede_caps = {
#     "platformName": "Android",
#     "platformVersion": "7.1.2",
#     "deviceName": "emulator-5554",
#     "appPackage": "com.tencent.wework",
#     "appActivity": ".launch.WwMainActivity",
#     # 'fullReset': False,
#     'noReset': 'true'
# }
#
# driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desirede_caps)
# org_page = OrgPage(driver)
# org_page.create_org("广州8866")
# time.sleep(5)
# org_page.my_quit()